package com.immediatus.engine.modifier;


import com.immediatus.engine.contracts.Interpolator;

public abstract class BaseDoubleValueSpanModifier<T> extends BaseSingleValueSpanModifier<T>{
	private final float _fromValueB;
	private final float _valueSpanB;

    public BaseDoubleValueSpanModifier(final float duration_, final float fromValueA_, final float toValueA_, final float fromValueB_, final float toValueB_) {
        super(duration_, fromValueA_, toValueA_);
        this._fromValueB = fromValueB_;
        this._valueSpanB = toValueB_ - fromValueB_;
    }

    public BaseDoubleValueSpanModifier(final float duration_, final float fromValueA_, final float toValueA_, final float fromValueB_, final float toValueB_, final Interpolator interpolator_) {
        super(duration_, fromValueA_, toValueA_, interpolator_);
        this._fromValueB = fromValueB_;
        this._valueSpanB = toValueB_ - fromValueB_;
    }

    public BaseDoubleValueSpanModifier(final float duration_, final float fromValueA_, final float toValueA_, final float fromValueB_, final float toValueB_, final IModifierListener<T> listener_) {
        super(duration_, fromValueA_, toValueA_, listener_);
        this._fromValueB = fromValueB_;
        this._valueSpanB = toValueB_ - fromValueB_;
    }

    public BaseDoubleValueSpanModifier(final float duration_, final float fromValueA_, final float toValueA_, final float fromValueB_, final float toValueB_,final IModifierListener<T> listener_, final Interpolator interpolator_) {
        super(duration_, fromValueA_, toValueA_, listener_, interpolator_);
        this._fromValueB = fromValueB_;
        this._valueSpanB = toValueB_ - fromValueB_;
    }

    protected BaseDoubleValueSpanModifier(final BaseDoubleValueSpanModifier<T> instance_) {
        super(instance_);
        this._fromValueB = instance_._fromValueB;
        this._valueSpanB = instance_._valueSpanB;
    }

	protected abstract void onSetInitialValues(final T item_, final float valueA_, final float valueB_);
	protected abstract void onChangeValues(final T item_, final float secondsElapsed_, final float valueA_, final float valueB_);

	@Override
	protected void onSetInitialValue(final T item_, final float valueA_) {
		this.onSetInitialValues(item_, valueA_, this._fromValueB);
	}

	@Override
	protected void onChangeValue(final T item_, final float secondsElapsed_, final float valueA_) {
        final float interpolation = getInterpolator().interpolate(secondsElapsed_ / getDuration());
		this.onChangeValues(item_, secondsElapsed_, valueA_, this._fromValueB + this._valueSpanB * interpolation);
	}
}
